package wml.clipstore.map;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import wml.clipstore.base.Entity;

/**
 * 
 * @author Miller.Wang
 * @since 2011-11-30
 */
class Interpreter {

	private static List<String> names = new ArrayList<String>();
	static{
		InputStream cfg = Interpreter.class.getResourceAsStream("/map.cfg");  
		try {
			read(cfg);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@SuppressWarnings("unchecked")
	static List<Class<? extends Entity>> getClasses()
			throws ClassNotFoundException {
		List<Class<? extends Entity>> classes = new ArrayList<Class<? extends Entity>>();
		for (String name : names)
			classes.add((Class<? extends Entity>) Class.forName(name));
		return classes;
	}

	private static void read(InputStream cfg) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(cfg));
		String clazz = null;
		while((clazz  = reader.readLine())!=null){
			names.add(clazz.trim());
		}
	}
}
